<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

  function merge(arr1, arr2) {
    const len1 = arr1.length;
    const len2 = arr2.length;
    let i = 0, j = 0;
    const result = [];

    while (i < len1 && j < len2) {
      if (arr1[i] < arr2[j]) {
        result.push(arr1[i]);
        i++;
      } else {
        result.push(arr2[j]);
        j++;
      }
    }

    // 将剩余的元素加入到结果数组中
    while (i < len1) {
      result.push(arr1[i]);
      i++;
    }

    while (j < len2) {
      result.push(arr2[j]);
      j++;
    }

    return result;
  }


const arr1 = [1, 2,3];
const arr2 = [2, 5,6];
console.log(merge(arr1, arr2)); 
  </script>
</body>
</html>